<template>
	<view>
		<view class="form">
			<u--form labelPosition="left" labelWidth="100" :model="model1" :rules="rules" ref="uForm">

				<u-form-item label="姓名" prop="Info.name" borderBottom>
					<u--input v-model="Info.name" border="none" placeholder="请输入联系人姓名"></u--input>
				</u-form-item>

				<u-form-item label="手机号" prop="Info.mobile" borderBottom>
					<u--input v-model="Info.mobile" border="none" placeholder="请输入联系人手机号"></u--input>
				</u-form-item>

				<u-form-item label="性别" prop="Info.sex" borderBottom>
					<u-radio-group v-model="Info.gander">
						<u-radio v-for="(item, index) in ['男','女']" :key="index" :label="item" :name="item" @change="Info.gander=item">
						</u-radio>
					</u-radio-group>
				</u-form-item>

				<u-form-item label="地址" prop="Info.address" borderBottom>
					<u--input v-model="Info.address" border="none" placeholder="请输入收货地址"></u--input>
				</u-form-item>

				<u-form-item label="门牌号" prop="Info.house_number" borderBottom>
					<u--input v-model="Info.house_number" border="none" placeholder="例:14号楼402室"></u--input>
				</u-form-item>


				<u-form-item label="设为默认地址" prop="Info.is_default" borderBottom>
					<u-switch v-model="Info.is_default" size="28"></u-switch>
				</u-form-item>
			</u--form>
		</view>

		<view class="save">
			<u-button type="error" shape="circle" @click="addAddress()">保存</u-button>
		</view>
	</view>
</template>

<script>
	import {getProvince,getImgSrc,getIp} from "../../../utils/tools.js";
	const CloudAddress=uniCloud.importObject("address")
	export default {
		data() {
			return {
				Info: {
					user_id:'',
					name: '',
					mobile: null,
					gander: "男",
					address: "",
					house_number: "",
					is_default: false
				},
			

			};
		},
		onShow(){
			this.Info.user_id = uni.getStorageSync("uni-id-pages-userInfo")._id;
			getIp().then(res=>{
				console.log(res);
			})
		},
		methods: {
			gomyaddress() {
				uni.redirectTo({
					url:"/pages/myAddress/myAddress"
				})
			},
			addAddress(){
				CloudAddress.addAddress(this.Info).then(res=>{
					console.log(res);
				})
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss">
	.form {
		width: 100%;
		padding: 0 20rpx;
	}

	.item4 {
		display: flex;
		justify-content: space-between;
	}

	.save {
		width: 100%;
		position: fixed;
		bottom: var(--window-bottom, 0);
		box-sizing: content-box;
	}
</style>